package org.liuhy.utils
{
	import mx.collections.ArrayCollection;
	
	import org.liuhy.line.AbstractLine;
//	import org.liuhy.line.ULine;
	import org.liuhy.node.FlowNode;
	public class LineUtils
	{
		public static var _LEN:int = 10;
		public function LineUtils()
		{			
		}
		public function calcX(p_value:int):int{
			return p_value - 5;
		}
		public function calcY(p_value:int):int{
			return p_value - 5;
		}
		
		public static function abs(p_value:int):int{
			if(p_value>=0) return p_value;
			return 0-p_value;
		}
		public static function removeLine(p_line:AbstractLine):void{
			if(null!=p_line){				
				p_line.cLine.removeChild(p_line);
			}
		}
		
		public static function removeInLine(p_uLine:AbstractLine):void{
			if(null!=p_uLine.in_flowFocusNode){
				var _flowNode:FlowNode = p_uLine.in_flowFocusNode.parent as FlowNode;
				_flowNode.removeInLine(p_uLine);
			}
		}
		public static function removeOutLine(p_uLine:AbstractLine):void{
			if(null!=p_uLine.out_flowFocusNode){
				var _flowNode:FlowNode = p_uLine.out_flowFocusNode.parent as FlowNode;
				_flowNode.removeOutLine(p_uLine);
			}
		}
		public static function getArrowLine(p_uLine:AbstractLine):AbstractLine{
			var _tLine:AbstractLine = p_uLine;
			while(null!=_tLine){
				if(null==_tLine.nextLine){
					return _tLine;
				}
				_tLine = _tLine.nextLine;				
			}
			return null;
		}
		public static function getFromLine(p_uLine:AbstractLine):AbstractLine{
			var _tLine:AbstractLine = p_uLine;
			while(null!=_tLine){
				if(null==_tLine.preLine){
					return _tLine;
				}
				_tLine = _tLine.preLine;				
			}
			return null;
		}
		//获取当前线段所有线段;
		public static function getAllLine(p_uLine:AbstractLine):ArrayCollection{
			var _array:ArrayCollection = new ArrayCollection();
			var _tmpLine:AbstractLine = null;
			_tmpLine = p_uLine;
			while(null!=_tmpLine){
				_array.addItem(_tmpLine);
				_tmpLine = _tmpLine.preLine;
			}
			_tmpLine = p_uLine.nextLine;
			while(null!=_tmpLine){
				_array.addItem(_tmpLine);
				_tmpLine = _tmpLine.nextLine;				
			}	
			return _array;	
		}
	}
}